package com.shell.arouter.demo.arouter;

import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.durian.base.frame.easyrouter.ActivityResult;
import com.durian.base.frame.easyrouter.OnActivityResultListener;
import com.durian.router.UserRouter;
import com.henanjianye.soon.communityo2o2.R;
import com.shell.arouter.ui.FragmentCommon;

import static com.shell.arouter.extend.ARouterPathKt.PAHT_FRAGMENT_AROUTER;

/**
 * 说明：FragmentARouter
 * <p/>
 * 作者：fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2019-11-13 11:37
 * <p/>
 * 版本：version 1.0
 */
@Route(path = PAHT_FRAGMENT_AROUTER)
public class FragmentARouter extends FragmentCommon {

    @Override
    public boolean isShowTitleBar() {
        return true;
    }

    @Override
    public boolean isShowTitleBarBack() {
        return true;
    }

    @Override
    public String bindTitleBarText() {
        return "ARouter";
    }

    @Override
    protected int getRootViewResID() {
        return R.layout.fragment_arouter;
    }

    @Override
    protected void onFirstUserVisible() {
        super.onFirstUserVisible();
        findViewById(R.id.btn_to_user_center).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserRouter.userCenter().setExtra(XRouter.Extra.NEED_LOGIN).withString("src", "设置Extras示例").navigation(activity(), new OnActivityResultListener() {
                    @Override
                    public void onReceiveResult(ActivityResult result) {
                        if (result.isSuccess("name")) {
                            shortToast(result.getData().getStringExtra("name"));
                        }
                    }
                });
            }
        });
        findViewById(R.id.btn_get_user_service).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IUserService service = UserRouter.getUserService();
                if (!service.isLogin()) {
                    shortToast("未登录");
                } else {
                    shortToast(service.getUser().getName());
                }
            }
        });
        findViewById(R.id.btn_get_contacts).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserRouter.userContacts("999").navigation(activity(), new OnActivityResultListener() {
                    @Override
                    public void onReceiveResult(ActivityResult result) {
                        if (result.isSuccess("name")) {
                            shortToast(String.format("获取成功：%s", result.getData().getStringExtra("name")));
                        }
                    }
                });
            }
        });
        findViewById(R.id.btn_login_exit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IUserService service = UserRouter.getUserService();
                if (service != null) {
                    service.loginExit();
                    shortToast("已经退出登录！");
                }
            }
        });
    }



}